var pic = './img/1.jpg'
var vm = new Vue({
    el: '#app',
    data: {//负责定义响应数据
        btnArr: ['综合排序', '距离最近', '销量最高', '筛选'],
        list: [
            { pic, name: '秋刀鱼', price: 35.00, count: 0 },
            { pic, name: '椒盐蘑菇', price: 45.00, count: 0 },
            { pic, name: '红烧鲤鱼', price: 85.00, count: 0 }
        ]
    },
    methods: {//负责定义方法
        add(item) {
            item.count++;
        },
        sub(item) {
            if (item.count > 0)
                item.count--;
        },
        clean() {
            this.list = [];
        },
        mysort(index){
            if( index == 0) {
                this.list.sort((a,b)=>{
                    return a.price - b.price;
                })
            }else if( index == 2 ){
                this.list.sort((a,b)=>{
                    return b.count - a.count;
                })
            }
        }
    }
})